<template>
  <div class="news-detail">
    <TopInfo />
    <TopTabs2 />
    <div class="content">
      <div class="news-content">
        <div class="header-info">
          <p class="header-title">
            {{ newData.NewTitle }}
          </p>
          <div class="header-content">
            <div class="content-info fl">
              <div>
                <i class="el-icon-s-platform"></i>来源：{{
                  newData.TypeName
                }}
              </div>
              <div>
                <i class="el-icon-timer"></i>时间：{{ newData.CreateDate }}
              </div>
            </div>
            <!-- <div class="save fr">
              <i
                :class="isCollect ? 'el-icon-star-on' : 'el-icon-star-off'"
                @click.stop="Save()"
              ></i>
            </div> -->
          </div>
        </div>
        <div class="bodyer-info">
          <div class="lefter-info fl">
            <!-- <div v-html="newData.Contents"></div> -->
            <p class="p-title">详情</p>
            <div v-html="newData.Content"></div>
            <!-- <p class="p-title">原文链接</p> -->
          </div>
          <!-- <div class="righter-info fr">
            <p class="p-title">热门政策</p>
            <ul class="news-list">
              <li
                @click="ToNewsDetail(item.Id)"
                v-for="item in newsDatas"
                :key="item.Id"
                :title="item.Title"
              >
                {{ item.Title }}
              </li>
            </ul>
          </div> -->
        </div>
      </div>
    </div>
    <BottomInfo />
  </div>
</template>

<script>
import BottomInfo from "../components/BottomInfo";
import TopInfo from "../components/TopInfo";
import TopTabs2 from "../components/TopTabs2";
export default {
  name: "NewsDetail",
  data() {
    return {
      id: "",
      newData: {},
      newsDatas: [],
      isCollect: false,
    };
  },
  mounted() {
    //console.log(this.$route.query);
    this.newData = this.$route.params.newdata;
    // console.log(this.newData);
    // this.GetList();
    // this.GetDetail(this.id);
  },
  methods: {
    GetList() {
      this.$axios({
        url: "/Policy/GetPolicyList",
        method: "post",
        data: {
          limit: 10,
          page: 1,
          day: 0,
          typeid: 1,
          title: "",
          userdata: this.$cookies.get("userdata"),
        },
        transformRequest: [
          function (data) {
            let ret = "";
            for (let it in data) {
              ret +=
                encodeURIComponent(it) +
                "=" +
                encodeURIComponent(data[it]) +
                "&";
            }
            return ret;
          },
        ],
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
      })
        .then((res) => {
          let rows = res.data.data;
          this.newsDatas = this.newsDatas.concat(rows);
        })
        .catch((err) => {
          //console.log(err);
        });
    },
    ToNewsDetail(id) {
      this.GetDetail(id);
    },
    GetDetail(id) {
      this.$axios({
        url: "/Policy/GetPolicyInfo",
        method: "post",
        data: {
          userdata: this.$cookies.get("userdata"),
          id,
        },
        transformRequest: [
          function (data) {
            let ret = "";
            for (let it in data) {
              ret +=
                encodeURIComponent(it) +
                "=" +
                encodeURIComponent(data[it]) +
                "&";
            }
            return ret;
          },
        ],
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
      })
        .then((res) => {
          //console.log(res.data.data);
          this.newData = res.data.data[0];
          //console.log(this.newData);
          this.isCollect = this.newData.IsCollect;
        })
        .catch((err) => {
          //console.log(err);
        });
    },
    Save() {
      this.$axios({
        url: "/User/AddUserCollect",
        method: "post",
        data: {
          userdata: this.$cookies.get("userdata"),
          policyid: this.id,
          typeid: 4,
        },
        transformRequest: [
          function (data) {
            let ret = "";
            for (let it in data) {
              ret +=
                encodeURIComponent(it) +
                "=" +
                encodeURIComponent(data[it]) +
                "&";
            }
            return ret;
          },
        ],
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
      })
        .then((res) => {
          //console.log(this.isCollect);
          //console.log(res.data.data);
          this.isCollect = !this.isCollect;
          this.$message({
            message: res.data.msg,
            type: "success",
          });
          // //console.log(this.IsCollect);
        })
        .catch((err) => {
          //console.log(err);
        });
    },
  },
  components: {
    TopInfo,
    TopTabs2,
    BottomInfo,
  },
};
</script>

<style scoped>
.content {
  background-color: #f4f6fc;
  padding: 25px 0;
  min-height: 500px;
}
.news-content {
  width: 1200px;
  margin: 0 auto;
}
.header-info {
  padding: 30px;
  box-sizing: border-box;
  background: #ffffff;
  box-shadow: 0px 0px 9px 0px rgba(9, 90, 255, 0.05);
}
.header-title {
  font-weight: bold;
  color: #333;
  font-size: 32px;
}
.header-content {
  margin-top: 30px;
  overflow: hidden;
}
.content-info {
  width: 1020px;
  background: #f6fafe;
  box-sizing: border-box;
  padding: 20px 30px;
  font-size: 16px;
  color: #333;
}
.content-info > div {
  line-height: 40px;
}
.content-info > div > i {
  margin-right: 10px;
  color: #095aff;
  float: left;
  position: relative;
  top: 11px;
  font-size: 18px;
}
.save i {
  color: #ffd34c;
  font-size: 30px;
  cursor: pointer;
}
.save {
  position: relative;
  top: 38px;
  right: 40px;
}
.bodyer-info {
  margin-top: 20px;
  overflow: hidden;
}
.lefter-info {
  width: 1200px;
  min-height: 600px;
  background: #ffffff;
  box-shadow: 0px 0px 9px 0px rgba(9, 90, 255, 0.05);
  box-sizing: border-box;
  margin-bottom: 50px;
  padding: 30px;
  font-size: 18px;
  /* color: #333; */
}
.p-title {
  font-weight: bold;
  font-size: 20px;
  color: #333;
  position: relative;
  margin: 20px 0;
  padding-left: 15px;
  box-sizing: border-box;
}
.p-title::after {
  content: "";
  position: absolute;
  width: 3px;
  height: 18px;
  background-color: #095aff;
  top: 7px;
  left: 0px;
}
.righter-info {
  width: 320px;
  min-height: 600px;
  background: #ffffff;
  box-shadow: 0px 0px 9px 0px rgba(9, 90, 255, 0.05);
  box-sizing: border-box;
  margin-bottom: 50px;
  padding: 10px 30px;
  color: #999999;
  font-size: 16px;
}
.news-list li {
  padding: 10px 0;
  border-top: 1px solid #dcdcdc;
  box-sizing: border-box;
  padding-left: 20px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.news-list li::after {
  content: "";
  position: absolute;
  top: 20px;
  left: 0;
  width: 6px;
  height: 6px;
  background: #999999;
  border-radius: 50%;
}
</style>